using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class Level : MonoBehaviour
{
    private GameObject gameObjectLock;
    private TextMeshProUGUI textNumber;
    private Image imageStar;
    [SerializeField] Sprite[] starSprites;

    private int mapID;
    private int id;

    void Awake()
    {
        this.gameObjectLock = transform.Find("Lock").gameObject;
        this.textNumber = transform.Find("Number").GetComponent<TextMeshProUGUI>();
        this.imageStar = transform.Find("Stars").GetComponent<Image>();

        this.gameObjectLock.SetActive(true);
        this.textNumber.enabled = false;
        this.imageStar.enabled = false;
    }

    /// <summary>
    /// 显示关卡入口
    /// </summary>
    /// <param name="id">第几关</param>
    /// <param name="starCount">获得了几颗星星</param>
    public void Show(int id, int starCount, int mapID)
    {
        if (starCount >= 0)
        {
            this.gameObjectLock.SetActive(false);
            this.textNumber.enabled = true;
            this.imageStar.enabled = true;
            this.textNumber.text = (id + 1).ToString();
            this.imageStar.sprite = this.starSprites[starCount];
        }

        this.mapID = mapID;
        this.id = id;
    }
    
    public void OnClick()
    {
        LevelManager.Instance.LoadGame(this.mapID, this.id);
    }
}
